class SharedResource {
    private int sharedValue = 0;

    public synchronized void increment() {
        sharedValue++;
    }

    public synchronized void printValue() {
        System.out.println("SharedValue: " + sharedValue);
    }
}

public class ThreadExample3 {
    public static void main(String[] args) {
        SharedResource resource = new SharedResource();

        // 线程1：多次调用increment()
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                resource.increment();
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        // 线程2：多次调用printValue()
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                resource.printValue();
                try {
                    Thread.sleep(150);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t1.start();
        t2.start();
    }
}